import r from './axios'
import qs from 'qs'


/**
 * 登录
 * @param data
 * username 用户名
 * password 密码
 */
export function userLogin(data: {
    username: any,
    password: any,
    loginType: any
} | any) {
    data['loginType'] = 'admin'
    return r.post('/admin/login', data)
}

/**
 * 注册
 * @param data
 * username 用户名
 * password 密码
 * confirmPassword 确认密码
 */
export function userRegister(data: {
    username: any,
    password: any,
    confirmPassword: any,
    role: 'ADMIN' | ''
}) {
    data.role = 'ADMIN'
    return r.post('/admin/login/register', data)
}

/**
 * 修改管理员
 * @param data
 */
export function putAdminSysUser(data: any) {
    return r.put('/admin/sysUser', data)
}

/**
 * 查询管理员
 * @param uid
 */
export function getByIdAdminSysUser(uid: any) {
    return r.get(`/admin/sysUser/${uid}`)
}

/**
 * 获取景点排行榜
 */
export function getArrrRank() {
    return r.get('/admin/data/attraction/rank')
}


export function getLineGraphDataApi() {
    return r.get('/admin/data/graph/line/data')
}

export function getTotalDataApi() {
    return r.get('/admin/data/total/data')
}

/**
 * 获取收藏排行榜
 */
export function getCollectRank() {
    return r.get('/admin/data/collect/rank')
}

/**
 * 获取评论排行榜
 */
export function getCommentRank() {
    return r.get('/admin/data/comment/rank')
}

/**
 * 获取资讯排行榜
 */
export function getNewsRank() {
    return r.get('/admin/data/news/rank')
}

/**
 * 获取路线排行榜
 */
export function getRouteRank() {
    return r.get('/admin/data/route/rank')
}

/**
 * 分页查询管理员账号
 * @param params
 */
export function getAdminSysUser(params: any) {
    return r.get('/admin/sysUser', {params})
}

/**
 * 删除管理员账号
 * @param params
 */
export function deleteAdminSysUser(params: any) {
    return r.delete('/admin/sysUser', {
        params: {ids: params},
        paramsSerializer: function (params) {
            return qs.stringify(params, {arrayFormat: 'repeat'})
        }
    })
}

/**
 * 用户信息分页查询
 */
export function getAdminUser(params: any) {
    return r.get('/admin/user', {params})
}

/**
 * 删除用户
 */
export function deleteAdminUser(params: any) {
    return r.delete('/admin/user', {
        params: {ids: params},
        paramsSerializer: function (params) {
            return qs.stringify(params, {arrayFormat: 'repeat'})
        }
    })
}

/**
 * 添加用户
 */
export function postAdminUser(data: any) {
    return r.post(`/admin/user`, data)
}

/**
 * 修改用户信息
 */
export function putAdminUser(data: any) {
    return r.put(`/admin/user`, data)
}

/**
 * 查询用户
 * @param uid
 */
export function getByIdAdminUser(uid: any) {
    return r.get(`/admin/user/${uid}`)
}


/**
 * 分页查询旅游路线信息
 * @param params
 * page 页码
 * size 页大小
 * keyword 关键字
 */
export function getAdminRoutes(params: {
    page: Number,
    size: Number,
    title: any
}) {
    return r.get('/admin/routes', {params})
}

export function getAdminRouteCategory() {
    return r.get('/admin/routes/category')
}

/**
 * 删除旅游路线信息
 * @param params ID数组
 */
export function deleteAdminRoutes(params: any) {
    return r.delete('/admin/routes', {
        params: {ids: params},
        paramsSerializer: function (params) {
            return qs.stringify(params, {arrayFormat: 'repeat'})
        }
    })
}

/**
 * 新增路线
 */
export function postAdminRoutes(data: any) {
    data['images'] = JSON.stringify(data['images'])
    return r.post('/admin/routes', data)
}

/**
 * 修改路线
 */
export function putAdminRoutes(data: any) {
    data['images'] = JSON.stringify(data['images'])
    return r.put('/admin/routes', data)
}

/**
 * 路线详情
 * @param id
 */
export function getByIdAdminRoutes(id: any) {
    return r.get(`/admin/routes/${id}`)
}

/**
 * 查询所有文章
 * @param params
 * page 页码
 * size 页大小
 * keyword 文章标题
 */
export function getAdminNews(params: { page: Number, size: Number, keyword: any }) {
    return r.get('/admin/news', {params})
}

/**
 * 获取资讯详情
 * @param id
 */
export function getByIdAdminNews(id: any) {
    return r.get(`/admin/news/${id}`)
}

/**
 * 添加资讯
 */
export function postAdminNews(data: any) {
    return r.post(`/admin/news`, data)
}

/**
 * 修改资讯
 */
export function putAdminNews(data: any) {
    return r.put(`/admin/news`, data)
}

export function getAdminNewsCategory() {
    return r.get('/admin/news/category')
}

/**
 * 删除资讯
 * @param params ID数组
 */
export function deleteAdminNews(params: any) {
    return r.delete('/admin/news', {
        params: {ids: params},
        paramsSerializer: function (params) {
            return qs.stringify(params, {arrayFormat: 'repeat'})
        }
    })
}

/**
 * 获取景点信息
 */
export function getAdminAttr(params: any) {
    return r.get('/admin/attraction', {params})
}

/**
 * 删除景点
 * @param params ID数组
 */
export function deleteAdminAttr(params: any) {
    return r.delete('/admin/attraction', {
        params: {ids: params},
        paramsSerializer: function (params) {
            return qs.stringify(params, {arrayFormat: 'repeat'})
        }
    })
}

/**
 * 添加景点
 */
export function postAdminAttr(data: any) {
    return r.post(`/admin/attraction`, data)
}

/**
 * 修改景点
 */
export function putAdminAttr(data: any) {
    return r.put(`/admin/attraction`, data)
}

/**
 * 获取资讯详情
 * @param id
 */
export function getByIdAdminAttr(id: any) {
    return r.get(`/admin/attraction/${id}`)
}

export function getCommentList(params: any) {
    return r.get('/admin/comment', {params})
}

export function deleteComment(params: any) {
    return r.delete('/admin/comment', {
        params: {ids: params},
        paramsSerializer: function (params) {
            return qs.stringify(params, {arrayFormat: 'repeat'})
        }
    })
}

export function changeCommentStatus(id: any) {
    return r.put(`/admin/comment/status/${id}`)
}

export function getCommentById(id: any) {
    return r.get(`/admin/comment/${id}`);
}